#include "led.h"
#include "gpio.h"

extern void delay_ms(unsigned int ms);

void hal_led_init(void)
{
	hal_gpio_init(RED_PORT, RED, ALT0);
	hal_gpio_mode(RED_PORT, RED, OUT_MODE);
	hal_gpio_init(BLUE_PORT, BLUE, ALT2);
	hal_gpio_mode(BLUE_PORT, BLUE, OUT_MODE);
	hal_gpio_init(GREEN_PORT, GREEN, ALT0);
	hal_gpio_mode(GREEN_PORT, GREEN, OUT_MODE);
}

void hal_led_flash(void)
{
	hal_gpio_write(RED_PORT, RED, HIGH_LEVEL);
	delay_ms(500);
	hal_gpio_write(RED_PORT, RED, LOW_LEVEL);
	delay_ms(500);
}


int hal_led_get_level(int color)
{
    switch (color) 
    {
        case RED:
            return RED_PORT->PAD & RED ? 1 : 0;
            break;
        case GREEN:
            return GREEN_PORT->PAD & GREEN ? 1 : 0;
            break;
        case BLUE:
            return BLUE_PORT->PAD & BLUE ? 1 : 0;
            break;
        default:
            break;
    }
    return 0;
}


